// test.ts

import { MockMethod } from 'vite-plugin-mock';
export default [
  {
    url: '/mock/api/enum',
    method: 'get',
    response: (data: any) => {
      return {
        code: 0,
        data: [
          {
            label: '北京',
            value: 'beijing',
          },
          {
            label: '上海',
            value: 'shanghai'
          },
          {
            label: '天津',
            value: 'tianjing'
          }
        ],
      };
    },
  },
  {
    url: '/mock/api/post',
    method: 'post',
    timeout: 0,
    response: {
      code: 0,
      data: {
        name: 'vben',
      },
    },
  },
  {
    url: '/mock/api/text',
    method: 'post',
    rawResponse: async (req, res) => {
      let reqbody = '';
      await new Promise((resolve) => {
        req.on('data', (chunk) => {
          reqbody += chunk;
        });
        req.on('end', () => resolve(undefined));
      });
      res.setHeader('Content-Type', 'text/plain');
      res.statusCode = 200;
      res.end(`hello, ${reqbody}`);
    },
  },
] as MockMethod[];
